# _*_coding:utf-8_*_
from utils.log_util import loggings as logger
from ATS.errHandler import errHandler

OK = 0


class PyvisaFake:
    def __init__(self):
        self.type = 'FAKE'
        self.instrHandle = 1

    def get_instrHandle(self):
        return 1

    def write(self, msg):
        """
        writes the string message to the instrument
        """
        # who_confront_err,err_code,err_msg,err_level
        logger.debug(f'FakePyVisa{msg}')

    def read_values(self, formats=None):
        """
        returns a list of decimal values (floats) sent from the instrument to the computer. See section 1.2 above. The list
        may contain only one element or may be empty.
        The optional format argument overrides the setting of values format
        """
        logger.debug(f'FakePyVisa{[1,2,3,4,5]}')
        return [1]  # ,2,3,4,5]

    def read(self):
        """
        returns a string sent from the instrument to the computer.
        """
        logger.debug(f'FakePyVisa read fake value')
        return 'Fake Read Value'

    def ask(self, msg):
        """
        sends the string message to the instrument and returns the answer string from the instrument
        """
        logger.debug('FakePyVisa ask fake value')
        return "1"

    def set_timeout(self, timeout):
        logger.debug(f'FakePyVisa{timeout}')

    def ask_for_values(self, msg, formats=None):
        """
        sends the string message to the instrument and reads the answer as a list of values, just as read values()
        does.
        The optional format argument overrides the setting of values format
        """
        logger.debug('FakePyVisa ask_for_values [1,2,3,4,5]')
        return [1, 2]  # ,3,4,5]

    def wait_for_srq(self, timeout=25):
        """
        Only for GPIB mode
        """
        logger.debug(f'FakePyVisa wait_for_srq{timeout}')
        return OK

    def spoll(self):
        logger.debug('FakePyVisa spoll')
        return 16
